package org.rency.crawler.fetch.repository.impl;

import javax.annotation.Resource;
import org.rency.crawler.domain.FetchHost;
import org.rency.crawler.fetch.repository.HostQueueRepository;
import org.rency.crawler.fetch.repository.MetaResourceRepository;
import org.rency.crawler.integration.cache.HostCacheClient;
import org.springframework.stereotype.Repository;

/**
 * 名称:HostQueueRepositoryImpl
 * 描述:${TODO}
 *
 * @author:rency
 * @version:V1.0.0
 * @JDK 1.8
 * @since 2017/11/22 21:48
 */
@Repository
public class HostQueueRepositoryImpl implements HostQueueRepository {

  @Resource
  private MetaResourceRepository metaResourceRepository;

  @Resource
  private HostCacheClient hostCacheClient;

  @Override
  public FetchHost get(String fetchHost) {
    return hostCacheClient.get(fetchHost);
  }

  @Override
  public boolean save(FetchHost fetchHost) {
    hostCacheClient.set(fetchHost,metaResourceRepository.getHostExpireTime());
    return true;
  }

  @Override
  public boolean update(FetchHost fetchHost) {
    hostCacheClient.update(fetchHost,metaResourceRepository.getHostExpireTime());
    return true;
  }

  @Override
  public long removeAll() {
    return hostCacheClient.removeAll();
  }
}
